<?php

/**
 * inside is:cachecontrol it is not possible to access env, content objects not
 * loaded inside the is:cachecontrol tag by cms:getobjects and the like.
 *
 * is-Tags are not allowed.
 *
 *
 */
class is_cachecontrolHandler {

    function startElement (phpinchains_parser_psp_PSPParser $sender, $attrs, $line)
    {
        if (!$attrs['cache'])
        {
            die ("Attribute val is missing in is:cachecontrol tag at line '$line'!\n");
        }
        $sender->appendCode('if (base_ApplicationContext::getInstance()->getDocumentContext()->getBuildMode() != base_templateEngine_BuildModes::$CACHE) {'."\n");
        $sender->beginCapture('cachecontrol');
    }

    function endElement (phpinchains_parser_psp_PSPParser $sender)
    {
        $sender->endCapture();
        $code = $sender->getCaptured('cachecontrol');
        $sender->clearCapture('cachecontrol');

        $sender->appendCode('} else { $out->write(\'<\'.\'?php
        $this->relativeFilePath = "content/cached_document.psp";
        $out->write(ob_get_contents());ob_end_clean();'.  str_replace("'", "\'", str_replace("\\", "\\\\", $code)).'ob_start(); ?>\'); }');
    }

}

?>
